//代理模式

var myImage = (function(){
    var imgNode = document.createElement('img')
    document.body.appendChild(imgNode)
    return{
        setSrc : function(src){
            imgNode.src=src;
        }
    }
})()

var proxyImage = (function () {
    var img = new Image;
    img.onload = function () {
        //console.log(this===img); true
        myImage.setSrc(this.src)
    }
    return {
        setSrc : function (src) {
            myImage.setSrc('loading.webp');
            img.src = src
        }
    }
})()
proxyImage.setSrc('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%253A%252F%252Fdingyue.ws.126.net%252F2021%252F0604%252Fcf462b52j00qu4yit0018c000hs00npc.jpg%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1649057698&t=28ac82cb6284c60a0a63b8b4428f5a43')


/******代理模式的意义 */
/***
 * 实现单一职责原则
 * 符合开放-封闭原则
 * 代理和本体接口的一致性
 */